﻿@model IEnumerable<BootyBay.Models.Category>

@if (ViewBag.ErrorMessage != null)
{
    <div>
        <p style="color:red">@ViewBag.ErrorMessage</p>
    </div>
}
@if (ViewBag.SuccessMessage != null)
{
    <div>
        <p style="color:green">@ViewBag.SuccessMessage</p>
    </div>
}
<div>
    <table>
        <tr>
            <th>Category Name</th>
            <th>Action</th>
        </tr>
        @if (Model.Count() == 0)
        {
            <tr>
                <td colspan="2">
                    No data.
                </td>
            </tr>
        }
        else
        {
            foreach (var item in Model)
            {
                <tr>
                    <td>
                        @using (Ajax.BeginForm("Category", new { id = item.Id }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "categoryListContent", InsertionMode = InsertionMode.Replace }, new { id = "editForm" + item.Id.ToString() }))
                        {
                            <input name="value" id="value" type="text" value="@item.Value" />
                        }
                    </td>
                    <td>
                        <a href="javascript:void(0);" onclick="$('form#editForm@(item.Id)').trigger('submit');">edit</a> |
                        @Ajax.ActionLink("delete", "DeleteCategory", new { id = item.Id }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "categoryListContent", InsertionMode = InsertionMode.Replace })
                    </td>
                </tr>
            }
        }
        <tr>
            <td>
                @using (Ajax.BeginForm("Category", new { id = 0 }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "categoryListContent", InsertionMode = InsertionMode.Replace }, new { id = "addForm" }))
                {
                    <input name="value" id="value" type="text" />
                }
            </td>
            <td>
                <a href="javascript:void(0)" onclick="$('form#addForm').trigger('submit');">add</a>
            </td>
        </tr>
    </table>
</div>